/**
 * 
 */
package servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import metier.Article;
import metier.Bean;
import persistence.Strategie;
import persistence.DAO.DAO;
import persistence.Factories.DAOFactory;


/**
 * @author hozakan
 *
 */
public class GoToMotoGP extends BaseServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8714683668798690265L;
	private static final Logger LOGGER = Logger.getLogger(GoToMotoGP.class);

	@Override
	protected void specificDoGet(HttpServletRequest request,
			HttpServletResponse response) {
		Strategie strat = Strategie.getInstance();
		DAOFactory factory = strat.getDAOFactory();
		DAO dao = factory.getDAO(new Article());
		List<Bean> beans = dao.getBeans();
		List<Article> listArtGP = new ArrayList<Article>();
		for (int i  =0 ;i<beans.size();i++)
			if (beans != null && ((Article)beans.get(i)).getIdCategorie() == 1) {
				listArtGP.add((Article) beans.get(i));
			}	
		request.getSession(false).setAttribute("articlesGP", listArtGP);

		try {
			request.getRequestDispatcher("/pages/motoGP.jsp").forward(request, response);
		} catch (ServletException e) {
			LOGGER.error("Impossible de rediriger vers la page motoGP");
		} catch (IOException e) {
			LOGGER.error("La page motoGP n'a pas été trouvée à l'endroit indiqué");
		}
	}

	@Override
	protected void specificDoPost(HttpServletRequest request,
			HttpServletResponse response) {
		//No job to do
	}
	
}
